const app = getApp()

Page({
  data: {
    todo: {},
    isEdit: false
  },
  onLoad(option) {
    const {id} = option
    const self = this
    wx.showLoading()
    app.http({
      url: `https://api.yizhanketang.cn/api/v1/todos/${id}`
    }).then(res => {
      self.setData({
        todo: res.data.data
      })
    }).catch((e) => {
      wx.showToast({
        icon: 'none',
        title: '网络错误，请刷新重试'
      })
    }).finally(() => {
      wx.hideLoading()
    })
  },
  edit() {
    const self = this
    if (!self.data.isEdit) {
      self.setData({
        isEdit: true
      })
    } else {
      console.log(self.data)
    }
  }
})